// 1. 导入http模块
const http = require('http');

// 导入fs
const fs = require('fs');

// 2. 创建http服务
const server = http.createServer((req, res) => {


    // 先获取请求地址
    let url = req.url;
    console.log(url);

    if (url === '/10-demo') {
        // 先读取html文件
        let str = fs.readFileSync('./10-demo.html');
        // console.log(str);
        res.setHeader('content-type', 'text/html;charset=utf-8');
        res.end(str);
    }

    if (url === '/11-demo2') {
        let str = fs.readFileSync('./11-demo2.html');
        res.setHeader('content-type', 'text/html;charset=utf-8');
        res.end(str);
    }

    if(url === '/13-1.css'){
        let str = fs.readFileSync('./13-1.css');
        res.setHeader('content-type', 'text/css;charset=utf-8');
        res.end(str);
    }

    if(url === '/1.jpg'){
        let str = fs.readFileSync('./1.jpg');
        res.setHeader('content-type', 'image/jpg;charset=utf-8');
        res.end(str);
    }


});

// 3.开启监听
// 端口号默认为80
server.listen(80, () => {
    console.log("启动成功");
});